package com.huxiu.holder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huxiu.DetailActivity;
import com.huxiu.R;
import com.huxiu.net.model.TuiJianItem;
import com.huxiu.utils.Constants;
import com.huxiu.utils.ImageLoaderOptions;
import com.huxiu.utils.Utils;
import com.huxiu.view.RefreshListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.lang.ref.WeakReference;


public class ShuoZhengJingHolder implements OnClickListener {

    @ViewInject(R.id.home_item_img)
    private ImageView img;

    @ViewInject(R.id.home_item_jianbian)
    private ImageView jianbian;

    @ViewInject(R.id.home_item_no_tuiguang)
    private LinearLayout noTuiGuang;

    @ViewInject(R.id.home_item_name)
    private TextView name;
    @ViewInject(R.id.home_item_time)
    private TextView time;

    @ViewInject(R.id.home_item_zan_num)
    private TextView zanNum;
    @ViewInject(R.id.home_item_pinglun_num)
    private TextView pingLunNum;

    @ViewInject(R.id.home_item_zhuanti)
    private TextView zhuanti;

    @ViewInject(R.id.home_item_tuiguang)
    private TextView tuiguang;


    @ViewInject(R.id.home_item_title)
    private TextView title;


    private static Activity mContext;
    private int position = -1;
    private RefreshListView lv_tabdetail_list;
    private static WeakReference<BaseAdapter> mAdapter;

    public void setAdapter(BaseAdapter adapter) {
        mAdapter = new WeakReference<>(adapter);
    }

    public ShuoZhengJingHolder(View view, Context context) {
        ViewUtils.inject(this, view);
        mContext = (Activity) context;
        title.setOnClickListener(this);
        img.setOnClickListener(this);
    }

    public ShuoZhengJingHolder(View view, Context context, int position) {
        ViewUtils.inject(this, view);
        mContext = (Activity) context;
        this.position = position;
        title.setOnClickListener(this);
        img.setOnClickListener(this);
    }

    private TuiJianItem mItem;

    public void bindItem(TuiJianItem item) {
        mItem = item;
        String times;
        times = Utils.getDateString(mItem.dateline);
        time.setText(times);
        zanNum.setText("  " + Integer.toString(mItem.agreenum));
        pingLunNum.setText("  " + Integer.toString(mItem.commentnum));
        name.setText(mItem.author);
        title.setText(mItem.title);
        ImageLoader.getInstance().displayImage(
                mItem.pic_path + Constants.IMAGE_WEBP, img, ImageLoaderOptions.options);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.home_item_title:
            case R.id.home_item_img:
                Intent intent = new Intent(mContext, DetailActivity.class);
                intent.putExtra("webUrl", mItem.url);
                mContext.startActivity(intent);
                break;

        }
    }


}
